import { Session } from "inspector";
import Cookies from "js-cookie";
import { CookieKey, LocalKey, SessionKey } from "./enums/CacheKey";
export class CookieCache {
    static set(key: string, value: any, expires: number = 3): void {
        Cookies.set(key, value, { expires })
    }
    static get(key: string): any {
        return Cookies.get(key)
    }
    static setJSON(key: string, jsonValue: object) {
        if (jsonValue != null) {
            CookieCache.set(key, JSON.stringify(jsonValue))
        }
    }
    static getJSON(key: string) {
        const value = CookieCache.get(key)
        if (value != null) {
            return JSON.parse(value)
        }
    }
    static clear() {
        for (let key in CookieKey) {
            Cookies.remove(key, undefined);
        }
    }
}
export class SessionCache {
    static set(key: string, value: any): void {
        sessionStorage.setItem(key, value)
    }
    static get(key: string): any {
        return sessionStorage.getItem(key)
    }
    static setJSON(key: string, jsonValue: object) {
        if (jsonValue != null) {
            SessionCache.set(key, JSON.stringify(jsonValue))
        }
    }
    static getJSON(key: string) {
        const value = SessionCache.get(key)
        if (value != null) {
            return JSON.parse(value)
        }
    }
    static remove(key: string) {
        sessionStorage.removeItem(key);
    }
    static clear() {
        for (let key in SessionKey) {
            sessionStorage.removeItem(key);
        }
    }
}
export class LocalCache {
    static set(key: string, value: any): void {
        localStorage.setItem(key, value)
    }
    static get(key: string): any {
        return localStorage.getItem(key)
    }
    static setJSON(key: string, jsonValue: object) {
        if (jsonValue != null) {
            LocalCache.set(key, JSON.stringify(jsonValue))
        }
    }
    static getJSON(key: string) {
        const value = LocalCache.get(key)
        if (value != null) {
            return JSON.parse(value)
        }
    }
    static remove(key: string) {
        localStorage.removeItem(key);
    }
    static clear() {
        for (let key in LocalKey) {
            localStorage.removeItem(key);
        }
    }
}

export { CookieKey, LocalKey, SessionKey }